#coding=utf-8

require "aio/core"

class Aio::Module::Cmd::Maipu::ShowCpu < Aio::Module::Cmd::Maipu
  include Aio::Module

  def initialize
    super({
      :cmd_full			=> "show cpu",
      :cmd_short		=> "sh cpu", 
      :author				=> "Elin",
      :description	=> "This is Maipu Command# show cpu",
      :ranking			=> Ranking_1,
      :platform			=> "all",
      :benchmark		=> {
        :used_percent		=> ["<", 70.0],		
      }
    })
  end

  def parse
    cont = self.context.dup
    useful[:cpu] = {}

    idle = 0
    cont.readline_match_block(/IDLE (?<cpu_idle>\d+)%/) do |block|
      idle = block[:cpu_idle].to_i
    end

    cont.readline_match_block(/TOTAL (?<cpu_total>\d+)%/) do |block|
      used = block[:cpu_total].to_i - idle
      block.warning_serious(useful[:cpu], :used_percent, self, string: used.to_s)
    end
  end
end
